﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PWS.Entities;

namespace PWS.DAL
{
    public class StoreLocationAccess
    {
        private static StoreLocation StoreLocationFields(DataRow Row)
        {
            StoreLocation sl = new StoreLocation();
            sl.StoreId = (int)Row["fldStoreId"];
            sl.StoreAddress = Row["fldStoreAddress"] as string;
            sl.StoreCity = Row["fldStoreCity"] as string;
            sl.StoreState = Row["fldStoreState"] as string;
            sl.StoreZip = (int)Row["fldStoreZip"];
            sl.StorePhone = Row["fldStorePhone"] as string;
            return sl;
        }

        private static StoreLocation[] DataSetToStoreLocationArray(DataSet ds5)
        {
            StoreLocation[] storelocation = new StoreLocation[ds5.Tables[0].Rows.Count];
            for (int i = 0; i < ds5.Tables[0].Rows.Count; ++i)
            {
                storelocation[i] = StoreLocationFields(ds5.Tables[0].Rows[i]);
            }
            return storelocation;
        }

        public static StoreLocation[] GetStoreLocation()
        {
            DataSet ds5 = SqlHelper.ExecuteDataset(ConfigurationManager.ConnectionStrings["PineDb"].ConnectionString, "StoreLocation_Get_StoreLocation");
            return DataSetToStoreLocationArray(ds5);
        }        
    }
}
